﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace DAO
{

	public class ForeigncurrencyDAO:IData<Foreigncurrency> 
 	{
		public ForeigncurrencyDAO(String myconnecString) : base(myconnecString) { }

		public override int OnSubmit(Foreigncurrency item, int t) {
			 return connec.ExecuteNonQuery("sp_Foreigncurrency", CommandType.StoredProcedure,new SqlParameter("@flag", t),
				 new SqlParameter("@" + Foreigncurrency.c_id, item.id), new SqlParameter("@" + Foreigncurrency.c_foreignCurrency, item.foreignCurrency),
				 new SqlParameter("@" + Foreigncurrency.c_rate, item.rate), new SqlParameter("@" + Foreigncurrency.c_updateDate, item.updateDate),
				 new SqlParameter("@" + Foreigncurrency.c_isActive, item.isActive)); 
		}

		public override Foreigncurrency GetItem(IDataReader dr)
		{
			Foreigncurrency obj = new Foreigncurrency();
			obj.id = Convert.ToInt32(dr[Foreigncurrency.c_id]);
			obj.foreignCurrency = Convert.ToString(dr[Foreigncurrency.c_foreignCurrency]);
			obj.rate = Convert.ToDecimal(dr[Foreigncurrency.c_rate]);
			obj.updateDate = Convert.ToDateTime(dr[Foreigncurrency.c_updateDate]);
			obj.isActive = Convert.ToInt32(dr[Foreigncurrency.c_isActive]);
			return obj;
		}

		public override List<Foreigncurrency> GetAll()
		{
			return GetAll("select * from " + Foreigncurrency.b_Foreigncurrency, CommandType.Text);
		}

		public override Foreigncurrency GetItemById(object id)
		{
			throw new NotImplementedException();
		}

	}

 }
